package cn.qingyun.gis.modules.enterprise.config;

import cn.hutool.core.util.StrUtil;
import cn.qingyun.gis.exception.CommonException;
import lombok.Data;

@Data
public class ManagerType {
    /**
     * 省管理员
     */
    public static final Integer PROVINCE = 1;
    /**
     * 地市管理员
     */
    public static final Integer CITY = 2;
    /**
     * 区县管理员
     */
    public static final Integer COUNTY = 3;
    /**
     * 网格管理员
     */
    public static final Integer AREA = 4;


    public static boolean validAuth(int managerType, String managerArea) {
        if (StrUtil.isBlank(managerArea)) {
            throw new CommonException("网格权限配置错误，请联系管理员");
        } else {
            String[] split = managerArea.split("\\.");

            if (PROVINCE.equals(managerType)) {
                return split.length == 1;
            } else if (CITY.equals(managerType)) {
                return split.length == 2;
            } else if (COUNTY.equals(managerType)) {
                return split.length == 3;
            } else {
                return true;
            }
        }
    }

    public static Integer calcManagerType(String allParentCode) {
        if (StrUtil.isBlank(allParentCode)) {
            throw new CommonException("网格权限配置错误，请联系管理员");
        } else {
            String[] split = allParentCode.split(",");

            return split.length;
        }
    }
}

